home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Harvest C / MPW Int & Lib / Interfaces / Sound.h < prev    next >
Text File  |  1991-04-17  |  16KB  |  511 lines

  1. /************************************************************
  2.  
  3. Created: Monday, January 28, 1991 at 6:54 PM
  4.     Sound.h
  5.     C Interface to the Macintosh Libraries
  6.  
  7.  
  8.         Copyright Apple Computer, Inc.    1986-1990
  9.         All rights reserved
  10.  
  11. ************************************************************/
  12.  
  13.  
  14. #ifndef __SOUND__
  15. #define __SOUND__
  16.  
  17. #ifndef __TYPES__
  18. #include <Types.h>
  19. #endif
  20.  
  21. #ifndef __FILES__
  22. #include <Files.h>
  23. #endif
  24.  
  25.  
  26. enum {
  27.  
  28.     swMode = -1,                            /* Sound Driver modes */
  29.     ftMode = 1,
  30.     ffMode = 0,
  31.  
  32.  
  33. #define synthCodeRsrc 'snth'                /* Resource types used by Sound Manager */
  34. #define soundListRsrc 'snd '
  35.  
  36. #define twelfthRootTwo 1.05946309434
  37.  
  38.     rate22khz = 0x56EE8BA3,                 /* 22254.54545 in fixed-point */
  39.     rate11khz = 0x2B7745D1,                 /* 11127.27273 in fixed-point */
  40.  
  41. /* synthesizer numbers for SndNewChannel */
  42.     squareWaveSynth = 1,                    /*square wave synthesizer*/
  43.     waveTableSynth = 3,                     /*wave table synthesizer*/
  44.     sampledSynth = 5,                       /*sampled sound synthesizer*/
  45.  
  46. /* old Sound Manager MACE synthesizer numbers */
  47.     MACE3snthID = 11,
  48.     MACE6snthID = 13,
  49.  
  50. /* command numbers for SndDoCommand and SndDoImmediate */
  51.     nullCmd = 0,
  52.     initCmd = 1,
  53.     freeCmd = 2,
  54.     quietCmd = 3,
  55.     flushCmd = 4,
  56.     reInitCmd = 5,
  57.  
  58.     waitCmd = 10,
  59.     pauseCmd = 11,
  60.     resumeCmd = 12,
  61.     callBackCmd = 13
  62. };
  63. enum {
  64.     syncCmd = 14,
  65.     emptyCmd = 15,
  66.  
  67.     tickleCmd = 20,
  68.     requestNextCmd = 21,
  69.     howOftenCmd = 22,
  70.     wakeUpCmd = 23,
  71.     availableCmd = 24,
  72.     versionCmd = 25,
  73.     totalLoadCmd = 26,
  74.     loadCmd = 27,
  75.  
  76.     scaleCmd = 30,
  77.     tempoCmd = 31,
  78.  
  79.     freqDurationCmd = 40,
  80.     restCmd = 41,
  81.     freqCmd = 42,
  82.     ampCmd = 43,
  83.     timbreCmd = 44,
  84.     getAmpCmd = 45,
  85.  
  86.     waveTableCmd = 60,
  87.     phaseCmd = 61
  88. };
  89. enum {
  90.  
  91.     soundCmd = 80,
  92.     bufferCmd = 81,
  93.     rateCmd = 82,
  94.     continueCmd = 83,
  95.     doubleBufferCmd = 84,
  96.     getRateCmd = 85,
  97.  
  98.     sizeCmd = 90,
  99.     convertCmd = 91,
  100.  
  101.     stdQLength = 128,
  102.     dataOffsetFlag = 0x8000,
  103.  
  104.     waveInitChannelMask = 0x07,
  105.     waveInitChannel0 = 0x04,
  106.     waveInitChannel1 = 0x05,
  107.     waveInitChannel2 = 0x06,
  108.     waveInitChannel3 = 0x07,
  109.  
  110. /* channel initialization parameters */
  111.     initPanMask = 0x0003,                   /* mask for right/left pan values */
  112.     initSRateMask = 0x0030,                 /* mask for sample rate values */
  113.     initStereoMask = 0x00C0,                /* mask for mono/stereo values */
  114.     initCompMask = 0xFF00,                  /* mask for compression IDs */
  115.  
  116.     initChanLeft = 0x0002                   /* left stereo channel */
  117. };
  118. enum {
  119.     initChanRight = 0x0003,                 /* right stereo channel */
  120.     initNoInterp = 0x0004,                  /* no linear interpolation */
  121.     initNoDrop = 0x0008,                    /* no drop-sample conversion */
  122.     initMono = 0x0080,                      /* monophonic channel */
  123.     initStereo = 0x00C0,                    /* stereo channel */
  124.     initMACE3 = 0x0300,                     /* MACE 3:1 */
  125.     initMACE6 = 0x0400,                     /* MACE 6:1 */
  126.  
  127.     initChan0 = 0x0004,                     /* channel 0 - wave table only */
  128.     initChan1 = 0x0005,                     /* channel 1 - wave table only */
  129.     initChan2 = 0x0006,                     /* channel 2 - wave table only */
  130.     initChan3 = 0x0007,                     /* channel 3 - wave table only */
  131.  
  132.     stdSH = 0x00,                           /* Standard sound header encode value */
  133.     extSH = 0xFF,                           /* Extended sound header encode value */
  134.     cmpSH = 0xFE,                           /* Compressed sound header encode value */
  135.  
  136.     notCompressed = 0,                      /* compression ID's */
  137.     twoToOne = 1,
  138.     eightToThree = 2,
  139.     threeToOne = 3,
  140.     sixToOne = 4,
  141.  
  142.     outsideCmpSH = 0                        /* MACE constants */
  143. };
  144. enum {
  145.     insideCmpSH = 1,
  146.     aceSuccess = 0,
  147.     aceMemFull = 1,
  148.     aceNilBlock = 2,
  149.     aceBadComp = 3,
  150.     aceBadEncode = 4,
  151.     aceBadDest = 5,
  152.     aceBadCmd = 6,
  153.     sixToOnePacketSize = 8,
  154.     threeToOnePacketSize = 16,
  155.     stateBlockSize = 64,
  156.     leftOverBlockSize = 32,
  157.  
  158.     firstSoundFormat = 0x0001,              /* general sound format */
  159.     secondSoundFormat = 0x0002,             /* special sampled sound format (HyperCard) */
  160.  
  161.     dbBufferReady = 0x00000001,             /* double buffer is filled */
  162.     dbLastBuffer = 0x00000004,              /* last double buffer to play */
  163.  
  164.     sysBeepDisable = 0x0000,                /* SysBeep() enable flags */
  165.     sysBeepEnable = 0x0001,
  166.  
  167.     unitTypeNoSelection = 0xFFFF,           /* unitTypes for AudioSelection.unitType */
  168.     unitTypeSeconds = 0x0000
  169. };
  170.  
  171.  
  172. /*            Structures for Sound Driver            */
  173.  
  174.  
  175. typedef unsigned char FreeWave[30001]; 
  176.  
  177. struct FFSynthRec {
  178.     short mode;
  179.     Fixed count;
  180.     FreeWave waveBytes;
  181. };
  182.  
  183. typedef struct FFSynthRec FFSynthRec;
  184. typedef FFSynthRec *FFSynthPtr;
  185.  
  186. struct Tone {
  187.     short count;
  188.     short amplitude;
  189.     short duration;
  190. };
  191.  
  192. typedef struct Tone Tone;
  193.  
  194.  
  195. typedef Tone Tones[5001];
  196.  
  197. struct SWSynthRec {
  198.     short mode;
  199.     Tones triplets;
  200. };
  201.  
  202. typedef struct SWSynthRec SWSynthRec;
  203. typedef SWSynthRec *SWSynthPtr;
  204.  
  205.  
  206. typedef unsigned char Wave[256]; 
  207. typedef Wave *WavePtr;
  208.  
  209. struct FTSoundRec {
  210.     short duration;
  211.     Fixed sound1Rate;
  212.     long sound1Phase;
  213.     Fixed sound2Rate;
  214.     long sound2Phase;
  215.     Fixed sound3Rate;
  216.     long sound3Phase;
  217.     Fixed sound4Rate;
  218.     long sound4Phase;
  219.     WavePtr sound1Wave;
  220.     WavePtr sound2Wave;
  221.     WavePtr sound3Wave;
  222.     WavePtr sound4Wave;
  223. };
  224.  
  225. typedef struct FTSoundRec FTSoundRec;
  226. typedef FTSoundRec *FTSndRecPtr;
  227.  
  228. struct FTSynthRec {
  229.     short mode;
  230.     FTSndRecPtr sndRec;
  231. };
  232.  
  233. typedef struct FTSynthRec FTSynthRec;
  234. typedef FTSynthRec *FTSynthPtr;
  235.  
  236.  
  237. typedef pascal void (*SndCompletionProcPtr)(void);
  238.  
  239. /*            Structures for Sound Manager            */
  240.  
  241. struct SndCommand {
  242.     unsigned short cmd;
  243.     short param1;
  244.     long param2;
  245. };
  246.  
  247. typedef struct SndCommand SndCommand;
  248.  
  249.  
  250. typedef long Time;                          /* in half milliseconds */
  251.  
  252.  
  253.  
  254. typedef struct SndChannel SndChannel;
  255. typedef SndChannel *SndChannelPtr;
  256.  
  257.  
  258. typedef pascal void (*SndCallBackProcPtr)(SndChannelPtr chan, SndCommand cmd);
  259.  
  260. struct SndChannel {
  261.     struct SndChannel *nextChan;
  262.     Ptr firstMod;                           /* reserved for the Sound Manager */
  263.     SndCallBackProcPtr callBack;
  264.     long userInfo;
  265.     Time wait;                              /* The following is for internal Sound Manager use only.*/
  266.     SndCommand cmdInProgress;
  267.     short flags;
  268.     short qLength;
  269.     short qHead;                            /* next spot to read or -1 if empty */
  270.     short qTail;                            /* next spot to write = qHead if full */
  271.     SndCommand queue[stdQLength];
  272. };
  273.  
  274. /* MACE structures */
  275. struct StateBlock {
  276.     short stateVar[stateBlockSize];
  277. };
  278.  
  279. typedef struct StateBlock StateBlock;
  280. typedef StateBlock *StateBlockPtr;
  281.  
  282. struct LeftOverBlock {
  283.     unsigned long count;
  284.     char sampleArea[leftOverBlockSize];
  285. };
  286.  
  287. typedef struct LeftOverBlock LeftOverBlock;
  288. typedef LeftOverBlock *LeftOverBlockPtr;
  289.  
  290. struct ModRef {
  291.     unsigned short modNumber;
  292.     long modInit;
  293. };
  294.  
  295. typedef struct ModRef ModRef;
  296.  
  297. struct SndListResource {
  298.     short format;
  299.     short numModifiers;
  300.     ModRef modifierPart[1];                 /*This is a variable length array*/
  301.     short numCommands;
  302.     SndCommand commandPart[1];              /*This is a variable length array*/
  303.     char dataPart[1];                       /*This is a variable length array*/
  304. };
  305.  
  306. typedef struct SndListResource SndListResource;
  307. typedef SndListResource *SndListPtr;
  308.  
  309. struct SoundHeader {
  310.     Ptr samplePtr;                          /* if NIL then samples are in sampleArea */
  311.     unsigned long length;                   /* length of sound in bytes */
  312.     Fixed sampleRate;                       /* sample rate for this sound */
  313.     unsigned long loopStart;                /* start of looping portion */
  314.     unsigned long loopEnd;                  /* end of looping portion */
  315.     unsigned char encode;                   /* header encoding */
  316.     unsigned char baseFrequency;            /* baseFrequency value */
  317.     char sampleArea[1];
  318. };
  319.  
  320. typedef struct SoundHeader SoundHeader;
  321. typedef SoundHeader *SoundHeaderPtr;
  322.  
  323.  
  324. struct CmpSoundHeader {
  325.     Ptr samplePtr;                          /* if nil then samples are in sample area */
  326.     unsigned long numChannels;              /* number of channels i.e. mono = 1 */
  327.     Fixed sampleRate;                       /* sample rate in Apples Fixed point representation */
  328.     unsigned long loopStart;                /* loopStart of sound before compression */
  329.     unsigned long loopEnd;                  /* loopEnd of sound before compression */
  330.     unsigned char encode;                   /* data structure used , stdSH, extSH, or cmpSH */
  331.     unsigned char baseFrequency;            /* same meaning as regular SoundHeader */
  332.     unsigned long numFrames;                /* length in frames ( packetFrames or sampleFrames ) */
  333.     extended AIFFSampleRate;                /* IEEE sample rate */
  334.     Ptr markerChunk;                        /* sync track */
  335.     Ptr futureUse1;                         /* reserved by Apple */
  336.     Ptr futureUse2;                         /* reserved by Apple */
  337.     StateBlockPtr stateVars;                /* pointer to State Block */
  338.     LeftOverBlockPtr leftOverSamples;       /* used to save truncated samples between compression calls */
  339.     unsigned short compressionID;           /* 0 means no compression, non zero means compressionID */
  340.     unsigned short packetSize;              /* number of bits in compressed sample packet */
  341.     unsigned short snthID;                  /* resource ID of Sound Manager snth that contains NRT C/E */
  342.     unsigned short sampleSize;              /* number of bits in non-compressed sample */
  343.     char sampleArea[1];                     /* space for when samples follow directly */
  344. };
  345.  
  346. typedef struct CmpSoundHeader CmpSoundHeader;
  347. typedef CmpSoundHeader *CmpSoundHeaderPtr;
  348.  
  349. struct ExtSoundHeader {
  350.     Ptr samplePtr;                          /* if nil then samples are in sample area */
  351.     unsigned long numChannels;              /* number of channels,  ie mono = 1 */
  352.     Fixed sampleRate;                       /* sample rate in Apples Fixed point representation */
  353.     unsigned long loopStart;                /* same meaning as regular SoundHeader */
  354.     unsigned long loopEnd;                  /* same meaning as regular SoundHeader */
  355.     unsigned char encode;                   /* data structure used , stdSH, extSH, or cmpSH */
  356.     unsigned char baseFrequency;            /* same meaning as regular SoundHeader */
  357.     unsigned long numFrames;                /* length in total number of frames */
  358.     extended AIFFSampleRate;                /* IEEE sample rate */
  359.     Ptr markerChunk;                        /* sync track */
  360.     Ptr instrumentChunks;                   /* AIFF instrument chunks */
  361.     Ptr AESRecording;
  362.     unsigned short sampleSize;              /* number of bits in sample */
  363.     unsigned short futureUse1;              /* reserved by Apple */
  364.     unsigned long futureUse2;               /* reserved by Apple */
  365.     unsigned long futureUse3;               /* reserved by Apple */
  366.     unsigned long futureUse4;               /* reserved by Apple */
  367.     char sampleArea[1];                     /* space for when samples follow directly */
  368. };
  369.  
  370. typedef struct ExtSoundHeader ExtSoundHeader;
  371. typedef ExtSoundHeader *ExtSoundHeaderPtr;
  372.  
  373. struct ConversionBlock {
  374.     short destination;
  375.     short unused;
  376.     CmpSoundHeaderPtr inputPtr;
  377.     CmpSoundHeaderPtr outputPtr;
  378. };
  379.  
  380. typedef struct ConversionBlock ConversionBlock;
  381. typedef ConversionBlock *ConversionBlockPtr;
  382.  
  383. struct SMStatus {
  384.     short smMaxCPULoad;
  385.     short smNumChannels;
  386.     short smCurCPULoad;
  387. };
  388.  
  389. typedef struct SMStatus SMStatus;
  390. typedef SMStatus *SMStatusPtr;
  391.  
  392. struct SCStatus {
  393.     Fixed scStartTime;
  394.     Fixed scEndTime;
  395.     Fixed scCurrentTime;
  396.     Boolean scChannelBusy;
  397.     Boolean scChannelDisposed;
  398.     Boolean scChannelPaused;
  399.     Boolean scUnused;
  400.     unsigned long scChannelAttributes;
  401.     long scCPULoad;
  402. };
  403.  
  404. typedef struct SCStatus SCStatus;
  405. typedef SCStatus *SCStatusPtr;
  406.  
  407. struct AudioSelection {
  408.     long unitType;
  409.     Fixed selStart;
  410.     Fixed selEnd;
  411. };
  412.  
  413. typedef struct AudioSelection AudioSelection;
  414. typedef AudioSelection *AudioSelectionPtr;
  415.  
  416. struct SndDoubleBuffer {
  417.     long dbNumFrames;
  418.     long dbFlags;
  419.     long dbUserInfo[2];
  420.     char dbSoundData[1];
  421. };
  422.  
  423. typedef struct SndDoubleBuffer SndDoubleBuffer;
  424. typedef SndDoubleBuffer *SndDoubleBufferPtr;
  425.  
  426.  
  427. typedef pascal void (*SndDoubleBackProcPtr) (SndChannelPtr channel,
  428.                                             SndDoubleBufferPtr doubleBufferPtr);
  429.  
  430. struct SndDoubleBufferHeader {
  431.     short dbhNumChannels;
  432.     short dbhSampleSize;
  433.     short dbhCompressionID;
  434.     short dbhPacketSize;
  435.     Fixed dbhSampleRate;
  436.     SndDoubleBufferPtr dbhBufferPtr[2];
  437.     SndDoubleBackProcPtr dbhDoubleBack;
  438. };
  439.  
  440. typedef struct SndDoubleBufferHeader SndDoubleBufferHeader;
  441. typedef SndDoubleBufferHeader *SndDoubleBufferHeaderPtr;
  442.  
  443.  
  444. #ifdef __cplusplus
  445. extern "C" {
  446. #endif
  447. pascal OSErr SndDoCommand(SndChannelPtr chan,const SndCommand *cmd,Boolean noWait)
  448.     = 0xA803; 
  449. pascal OSErr SndDoImmediate(SndChannelPtr chan,const SndCommand *cmd)
  450.     = 0xA804; 
  451. pascal OSErr SndNewChannel(SndChannelPtr *chan,short synth,long init,SndCallBackProcPtr userRoutine)
  452.     = 0xA807; 
  453. pascal OSErr SndDisposeChannel(SndChannelPtr chan,Boolean quietNow)
  454.     = 0xA801; 
  455. pascal OSErr SndPlay(SndChannelPtr chan,Handle sndHdl,Boolean async)
  456.     = 0xA805; 
  457. pascal OSErr SndAddModifier(SndChannelPtr chan,ProcPtr modifier,short id,
  458.     long init)
  459.     = 0xA802; 
  460. pascal OSErr SndControl(short id,SndCommand *cmd)
  461.     = 0xA806; 
  462.  
  463. pascal void SetSoundVol(short level); 
  464. #pragma parameter GetSoundVol(__A0)
  465. pascal void GetSoundVol(short *level)
  466.     = {0x4218,0x10B8,0x0260}; 
  467. pascal void StartSound(const void *synthRec,long numBytes,SndCompletionProcPtr completionRtn); 
  468. pascal void StopSound(void); 
  469. pascal Boolean SoundDone(void); 
  470.  
  471. pascal NumVersion SndSoundManagerVersion(void)
  472.     = {0x203C,0x000C,0x0008,0xA800}; 
  473. pascal OSErr SndStartFilePlay(SndChannelPtr chan,short fRefNum,short resNum,
  474.     long bufferSize,void *theBuffer,AudioSelectionPtr theSelection,ProcPtr theCompletion,
  475.     Boolean async)
  476.     = {0x203C,0x0D00,0x0008,0xA800}; 
  477. pascal OSErr SndPauseFilePlay(SndChannelPtr chan)
  478.     = {0x203C,0x0204,0x0008,0xA800}; 
  479. pascal OSErr SndStopFilePlay(SndChannelPtr chan,Boolean async)
  480.     = {0x203C,0x0308,0x0008,0xA800}; 
  481. pascal OSErr SndChannelStatus(SndChannelPtr chan,short theLength,SCStatusPtr theStatus)
  482.     = {0x203C,0x0010,0x0008,0xA800}; 
  483. pascal OSErr SndManagerStatus(short theLength,SMStatusPtr theStatus)
  484.     = {0x203C,0x0014,0x0008,0xA800}; 
  485. pascal void SndGetSysBeepState(short *sysBeepState)
  486.     = {0x203C,0x0018,0x0008,0xA800}; 
  487. pascal OSErr SndSetSysBeepState(short sysBeepState)
  488.     = {0x203C,0x001C,0x0008,0xA800}; 
  489. pascal OSErr SndPlayDoubleBuffer(SndChannelPtr chan,SndDoubleBufferHeaderPtr theParams)
  490.     = {0x203C,0x0020,0x0008,0xA800}; 
  491.  
  492. pascal NumVersion MACEVersion(void)
  493.     = {0x203C,0x0000,0x0010,0xA800}; 
  494. pascal void Comp3to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  495.     const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  496.     = {0x203C,0x0004,0x0010,0xA800}; 
  497. pascal void Exp1to3(const void *inBuffer,void *outBuffer,unsigned long cnt,
  498.     const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  499.     = {0x203C,0x0008,0x0010,0xA800}; 
  500. pascal void Comp6to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  501.     const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  502.     = {0x203C,0x000C,0x0010,0xA800}; 
  503. pascal void Exp1to6(const void *inBuffer,void *outBuffer,unsigned long cnt,
  504.     const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  505.     = {0x203C,0x0010,0x0010,0xA800}; 
  506. #ifdef __cplusplus
  507. }
  508. #endif
  509.  
  510. #endif
  511.